using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace Jonathan.Tabber
{
    public class GradientPanel : FlowLayoutPanel
    {
        private Color m_Color1;
        private Color m_Color2;
        private LinearGradientMode m_GradientMode;

        public GradientPanel()
        {
            this.m_Color1 = SystemColors.Menu;
            this.m_Color2 = SystemColors.MenuBar;
            this.m_GradientMode = LinearGradientMode.Vertical;
            this.WrapContents = false;
        }

        protected override void OnResize(EventArgs eventargs)
        {
            base.OnResize(eventargs);
            this.Invalidate(true);
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            if (this.Width > 0 & this.Height > 0)
            {
                //base.OnPaintBackground(e);
                LinearGradientBrush lBr = new LinearGradientBrush(this.ClientRectangle, this.m_Color1, this.m_Color2, this.m_GradientMode);
                e.Graphics.FillRectangle(lBr, this.ClientRectangle);
                lBr.Dispose();
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            int left = 0;
            for (int a = 0; a < this.Controls.Count; a++)
            {
                if (((TabButton)this.Controls[a]).Page.Selected)
                {
                    e.Graphics.DrawLine(Pens.Black, new Point(left, this.Height - 1), new Point(this.Controls[a].Left, this.Height - 1));
                }
                else
                {
                    e.Graphics.DrawLine(Pens.Black, new Point(left, this.Height - 1), new Point(this.Controls[a].Right, this.Height - 1));
                }
                left = this.Controls[a].Right - 1;
            }
            e.Graphics.DrawLine(Pens.Black, new Point(left, this.Height - 1), new Point(this.Width, this.Height - 1));
        }

        /// <summary>
        /// Gets or Sets the First Color...
        /// </summary>
        public Color Color1
        {
            get { return this.m_Color1; }

            set { this.m_Color1 = value; }
        }

        /// <summary>
        /// Gets or Sets the Second Color...
        /// </summary>
        public Color Color2
        {
            get { return this.m_Color2; }

            set { this.m_Color2 = value; }
        }

        /// <summary>
        /// Gets or Sets the Gradient Mode...
        /// </summary>
        public LinearGradientMode GradientMode
        {
            get { return this.m_GradientMode; }

            set { this.m_GradientMode = value; }
        }
    }
}
